package emulator.analyzer.sid;

import java.io.PrintStream;

import emulator.hardware.HwWord;
import emulator.util.AddressRange;
import emulator.util.file.FileInfo;
import emulator.util.file.FileInfoSid;

public class SidInfo {
	private int start_address;
	private int block_size;
	private int init_address;
	private int exec_address;
	private int song_count;
	private int start_song;
	private String title;
	private String author;
	private String year;
	
	public void init(int start_address, int block_size)
	{
		this.start_address = start_address;
		this.block_size = block_size;
		init_address = start_address;
		exec_address = start_address+3;
		song_count = 1;
	}

	public SidInfo(FileInfo info) {
		init(info.getStartAddress(), info.getBlockSize());
		
		FileInfoSid sid_file = null;
		try {
			sid_file = (FileInfoSid)info;
		} catch (ClassCastException e) {
		}
		if (sid_file != null)
		{
			song_count = sid_file.getSongCount();
			if (sid_file.getInitAddress() > 0)
				init_address = sid_file.getInitAddress();
			if (sid_file.getExecAddress() > 0)
				exec_address = sid_file.getExecAddress();
			start_song = sid_file.getStartSong();
			title = sid_file.getTitle();
			author = sid_file.getAuthor();
			year = sid_file.getYear();
		}
	}

	public int getStartAddress() {
		return start_address;
	}

	public int getBlockSize() {
		return block_size;
	}

	public int getInitAddress() {
		return init_address;
	}

	public int getExecAddress() {
		return exec_address;
	}

	public int getSongCount() {
		return song_count;
	}

	private int getStartSong() {
		return start_song;
	}

	public void print(PrintStream out) {
		out.println("Code: " + getCodeRange());
		out.println("  Init: $" + new HwWord(getInitAddress()));
		out.println("  Play: $" + new HwWord(getExecAddress()));
		out.println(" Songs: " + getSongCount() + "  Default: " + getStartSong());
	}

	public AddressRange getCodeRange() {
		AddressRange range = new AddressRange();
		range.setStart(getStartAddress());
		range.setEnd(getStartAddress() + getBlockSize() - 1);
		return range;
	}

	public String getTitle() {
		return title;
	}

	public String getAuthor() {
		return author;
	}

	public String getYear() {
		return year;
	}

}
